package com.example.administrator.mvp.module.user;

import android.support.annotation.Nullable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.mvp.R;
import com.example.administrator.mvp.base.BaseActivity;
import com.example.administrator.mvp.model.entity.UserEntity;
import com.example.administrator.mvp.model.user.UserModel;

/**
 * 用户信息页面
 */
public class UserActivity extends BaseActivity<UserPresenter> implements UserContract.View {
    TextView tv_name, tv_age;
    ImageView iv;

    //假设用户已经完成登录，并本地存储下了登录令牌
    String token = "1ab25inibj3882lkhanab";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);

        //初始化控件
        tv_name = findViewById(R.id.tv_name);
        tv_age = findViewById(R.id.tv_age);
        iv = findViewById(R.id.iv);

        //初始化Presenter
        presenter = new UserPresenter(this, new UserModel(this));
        //获取用户信息
        presenter.getUserInfo(token);
    }

    /**
     * 显示用户信息
     *
     * @param entity
     */
    @Override
    public void showUserInfo(UserEntity entity) {
        tv_name.setText("用户名：" + entity.getName());
        tv_age.setText("年龄：" + entity.getAge());
        Glide.with(this).load(entity.getImage()).into(iv);
    }
}
